/**
 * @Author Yunfeng Bai
 *
 * 2010-10-30
 */
package geometry;

import javax.media.opengl.GL2;
import javax.vecmath.Color3f;

import collision.ASDFOctree;
import collision.BoundingBox;
import collision.OBBTree;

/**
 * Drawable is a general class that provides triangle meshes for drawing.
 * 
 * It uses displays lists to draw, In case we have not built the display list,
 * build() will be called in draw().
 * 
 * It should also supports getting bounding box(AABB) and bounding sphere.
 * Bounding AABB is used in getting bounding sphere,
 * as well for the initial dividing space for ASDF tree;
 * while bounding sphere is used as bounding volume in rigid body collision currently. 
 */
public abstract class Drawable
{
    protected int _listNum = -1;
    protected Color3f _color = new Color3f();
    protected ASDFOctree asdfTree = null;
    
    public abstract void build(GL2 gl);
    public abstract TriangleMesh getTriangleMesh();
    public abstract BoundingBox getBoundingBox();
    
    public ASDFOctree getASDFTree()
    {
    	return asdfTree;
    }

    public void draw(GL2 gl)
    {
        if (_listNum == -1)
        {
            build(gl);
        }
        gl.glColor3f(_color.x, _color.y, _color.z);
        gl.glCallList(_listNum);
    }

    public void setColor(Color3f color_)
    {
        _color = color_;
    }

    public Color3f getColor()
    {
        return _color;
    }
    
    public void set(Drawable d)
    {
    	_listNum = d._listNum;
    	_color.set(d._color);
    }

	public void initASDF(OBBTree tree)
	{
		if (asdfTree == null)
			asdfTree = new ASDFOctree(this, tree);
	}
}
